<link type="text/css" href="/admins/js/pagerView/pager-view.css" rel="stylesheet" />
<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/admins/js/jquery/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="/admins/js/jquery/jquery.ui.datepicker-zh-CN.js"></script>
<script type="text/javascript" src="/admins/js/pagerView/pager-view.js"></script>
<?php
if($this->ma == 2){
    echo '<script language="javascript" type="text/javascript">alert("发生未知错误！");</script>';
}else if($this->ma == 1){
    echo '<script language="javascript" type="text/javascript">alert("修改成功！");</script>';
}else if($this->ma == 3){
    echo '<script language="javascript" type="text/javascript">alert("添加成功！");</script>';
}else if($this->ma == 4){
    echo '<script language="javascript" type="text/javascript">alert("该淘宝账号已存在！");</script>';
}
?>
<form action="/admini/manageadmin/taobaoapi/"  method="get" style="margin:0px" id="form1">
    <div style=" border:1px solid #DDDDDD; padding:2px; margin:2px;line-height: 36px;" id='sel'> 
        <label for="quick">淘宝名称：</label><input type="text" id="name" name="name" value="<?php echo $this->name; ?>" />
        <input type="submit" id="queryButton" name="queryButton" value="查询"/>
    </div>
</form>

<div class="dataTable">
    <table>         
    <tfoot>
      <tr><td colspan="14"><input class="button" id="add-button" type="button" value="添加" /><input class="button" id="del-button" type="button" value="删除" /></td></tr>
    </tfoot>
        <tr>
            <th class="w1" width="5px"></th>
            <th class="w2" width="15%" nowrap>淘宝名称</th>
            <th class="w3" width="15%" nowrap>淘宝Api</th>
            <th class="w4" width="15%" nowrap>淘宝编号</th>
            <th class="w5" width="30%" nowrap>sessionkey</th>
            <th class="w6" width="30%" nowrap>FreshToken</th>
        </tr>  

        <?php
        if ($this->taobaolist) {
            foreach ($this->taobaolist as $Item) {
                ?>
                <tr>
                    <td class="w1" width="5px" align="center"><input type="checkbox" value="<?php echo $Item->id; ?>" class="checkbox-del" name='checkbox'  /></td>
                    <td class="w2" align="center"><a href="javascript:void(0)" id="edit-a" class="indexa" name="<?php echo $Item->id; ?>"><?php echo $Item->taobaoname; ?></a></td>
                    <td class="w3" align="center"><?php echo $Item->api; ?></td>
                    <td class="w4" align="center"><?php echo $Item->taobaoSign; ?></td>
                    <td class="w5" align="center"><?php echo $Item->sessionkey; ?></td>
                    <td class="w6" align="center"><?php echo $Item->freshtoken; ?></td>
                </tr>
        <?php
    }
}
?>
    </table>
</div>                
<div class="toolbar">
    <?php echo $this->partial('paging.phtml', array("pages" => $this->taobaoall,"pamas"=>"name=".$this->name)); ?>
</div>
<div class="tanchuang" style="display:none;">
    <div class="nui-msgbox">
        <div class="nui-msgbox-hd" id="edithead" style="display:none;">更新淘宝API</div>
        <div class="nui-msgbox-hd" id="addhead" style="display:none;">添加淘宝API</div>
        <a class="nui-msgbox-close" title="关闭" id="exitissue"><b></b></a>
    </div>
    <div class="neirbox">
        <form method="post" action="/admini/manageadmin/taobaoapi/" id="formissue">
	<table>
            <tr>
            	<td class="askl">淘宝名称：</td>
                <td><div id="taobaoneme"></div></td>
            </tr>
            <tr>
            	<td class="askl">淘宝Api：</td>
                <td><input type="text" id="api" name="api" value="" class="input w400"/></td>
            </tr>
            <tr>
            	<td class="askl">sessionkey：</td>
                <td><input class="input w400" type="text" id="sessionkey" name="sessionkey" value="" /></td>
            </tr>
        	<tr>
            	<td class="askl">FreshToken：</td>
                <td><input class="input w400" type="text" id="freshtoken" name="freshtoken" value="" /></td>
            </tr>
        </table>
        <div class="neirboxok">
            <input type="hidden" id="id" name="id" value="" />
            <input type="hidden" id="operate" name="operate" value="" />
            <a class="anvbotton" href="javascript:void(0)" id="subissue"><span>确认提交</span></a>
        </div>  
        </form>
    </div>
</div>
<div class="houtai_overlay" style="display:none;"></div>
<?php
if(isset($this->message) && $this->message!=""){
    echo '<script language="javascript" type="text/javascript">alert("'. $this->message .'")</script>';
}

?>
<script language="javascript">
    $("#subissue").live("click",function(){
       var api = $(".neirbox #api").val(); 
       var sessionkey = $(".neirbox #sessionkey").val(); 
       var freshtoken = $(".neirbox #freshtoken").val(); 
       if(api == ""){
           alert("淘宝Api不能为空！");
           return false;
       }else if(sessionkey == ""){
           alert("淘宝sessionkey不能为空！");
           return false;
       }else if(freshtoken == ""){
           alert("淘宝freshtoken不能为空！");
           return false;
       }else{
           $("#formissue").submit();
       }
    });
    $("#exitissue").live("click",function(){
        $("div.houtai_overlay").attr("style","display:none;");
        $("div.tanchuang").attr("style","display:none;");
    });
    $("#edit-a").live("click",function(){
       var id = $(this).attr("name");
       $.ajax({
            type: 'POST',
            url: "/admini/manageadmin/bytaobao/id/"+id,
            success: function(data) {
                if(data.type == 1){
                    $(".neirbox div#taobaoneme").text(data.taobaoname);
                    $(".neirbox #api").val(data.api);
                    $(".neirbox #sessionkey").val(data.sessionkey);
                    $(".neirbox #freshtoken").val(data.freshtoken);
                    $(".neirbox input#id").val(id);
                    $(".neirbox input#operate").val("edittaobao");
                    $("div.houtai_overlay").attr("style","display:block;");
                    $("div.tanchuang").attr("style","display:block;");
                    $("div#edithead").attr("style","display:block;");
                    $("div#addhead").attr("style","display:none;");
                }else{
                    alert("发生未知错误！");
                }
           }
       });
    });
    $('#add-button').click(function(){
        $(".neirbox #api").val("");
        $(".neirbox #sessionkey").val("");
        $(".neirbox #freshtoken").val("");
        $(".neirbox input#id").val("");
        $(".neirbox div#taobaoneme").html('<input type="text" id="taobaoname" name="taobaoname" value="" class="input w400"/>');
        $(".neirbox input#operate").val("addtaobao");
        $("div.houtai_overlay").attr("style","display:block;");
        $("div.tanchuang").attr("style","display:block;");
        $("div#edithead").attr("style","display:none;");
        $("div#addhead").attr("style","display:block;");
    });
    $('#del-button').click(function(){
        var idlist = "";
        $('input[name="checkbox"]:checked').each(function(){    
		idlist += $(this).val()+",";
	});
        if(idlist == ''){
            alert("请选择用户");
            return false;
        }else{
            if(confirm("您确定删除该淘宝Api信息？","提示信息")){     
                $.ajax({
                    type: 'POST',
                    url: "/admini/manageadmin/deltaobao/idlist/"+idlist,
                    success: function(data) {
                        if(data == 1){
                            alert("删除成功！");
                            location.href='/admini/manageadmin/taobaoapi/';
                        }
                    }
                });
            }
        }
    });
    
</script>
